package com.example.myapplication8_3;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private RatingBar dramaRating, pictureRating, soundRating;
    private TextView dramaValue, pictureValue, soundValue, resultText;
    private Button submitBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化组件
        dramaRating = findViewById(R.id.dramaRating);
        pictureRating = findViewById(R.id.pictureRating);
        soundRating = findViewById(R.id.soundRating);
        dramaValue = findViewById(R.id.dramaValue);
        pictureValue = findViewById(R.id.pictureValue);
        soundValue = findViewById(R.id.soundValue);
        resultText = findViewById(R.id.resultText);
        submitBtn = findViewById(R.id.submitBtn);

        // 设置监听器
        dramaRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                dramaValue.setText(String.valueOf(rating));
            }
        });

        pictureRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                pictureValue.setText(String.valueOf(rating));
            }
        });

        soundRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                soundValue.setText(String.valueOf(rating));
            }
        });

        // 提交按钮点击事件
        submitBtn.setOnClickListener(v -> {
            String result = "剧情:" + dramaRating.getRating() + "分 画面:" + pictureRating.getRating() + "分 音效:" + soundRating.getRating() + "分";
            resultText.setText(result);
        });
    }
}